package phone.qyg.com.qyg.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.app.adapter.recycler.MultiItemTypeAdapter;
import com.app.adapter.recycler.base.ItemViewDelegate;
import com.app.adapter.recycler.base.ViewHolder;
import com.app.utils.CommonUtil;
import com.app.utils.OptionImageUtils;

import java.util.List;

import phone.qyg.com.qyg.R;
import phone.qyg.com.qyg.model.MapTheme;

/**
 * 作者：lblbh on 2017/6/30 16:39
 * 邮箱：lanbuhan@163.com
 * 功能：TODO
 */
public class FitnessMapAdapter extends MultiItemTypeAdapter<MapTheme> {

    OnFitnessMapTitle onFitnessMapTitle;

    public FitnessMapAdapter(Context context, List<MapTheme> datas, OnFitnessMapTitle onFitnessMapTitle) {
        super(context, datas);
        this.onFitnessMapTitle = onFitnessMapTitle;
        addItemViewDelegate(new FitnessLineOne());
        addItemViewDelegate(new FitnessLineTwo());
    }


    public class FitnessLineOne implements ItemViewDelegate<MapTheme> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_fit_map_one;
        }

        @Override
        public boolean isForViewType(MapTheme item, int position) {
            return (item.type != 926);
        }

        @Override
        public void convert(ViewHolder holder, final MapTheme model, int position) {
            holder.setText(R.id.item_title,model.title);
            holder.setInVisible(R.id.item_title,(CommonUtil.isRequestStr(model.title))?true:false);
            holder.setVisible(R.id.item_left,((position % 4) == 0)?true:false);
            holder.setBackgroundColor(R.id.item_left, Color.parseColor(model.color));
            holder.setOnClickListener(R.id.item_title, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(onFitnessMapTitle != null && CommonUtil.isRequestStr(model.title))
                        onFitnessMapTitle.onClick(model.title);
                }
            });
        }
    }

    public class FitnessLineTwo implements ItemViewDelegate<MapTheme> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_fit_map_two;
        }

        @Override
        public boolean isForViewType(MapTheme item, int position) {
            return (item.type == 926);
        }

        @Override
        public void convert(ViewHolder holder, MapTheme model, int position) {
            holder.setText(R.id.item_title,model.title);
            if(CommonUtil.isRequestStr(model.color)){
                holder.setTextColor(R.id.item_title,Color.parseColor(model.color));
            }
            holder.setInVisible(R.id.item_title,(CommonUtil.isRequestStr(model.title))?true:false);
            holder.setInVisible(R.id.item_img,(CommonUtil.isRequestStr(model.title))?true:false);
            if(CommonUtil.isRequestStr(model.imgUrl)){
                holder.setImage(R.id.item_img,model.imgUrl, OptionImageUtils.getRectRatio43());
            }

        }
    }

    public interface OnFitnessMapTitle{
        public void onClick(String title);
    }
}
